package com.gidgabs.modules.entity;

import com.baomidou.mybatisplus.activerecord.Model;
import com.gidgabs.config.GidgabsContants;
import com.gidgabs.dto.TbUserDto;
import io.swagger.models.auth.In;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * <p>
 * 用户
 * </p>
 *
 * @author theodo
 * @since 2017-10-28
 */
public class TbUser extends Model<TbUser> {

	private static final long serialVersionUID = 1L;

	private Integer userId;
	//用户编码
	private String userCode;
	//昵称
	private String userName;
	//电话
	private String mobile;
	/**电子邮箱*/
	private String email;
	//登录密码
	private String password;
	//支付密码
	private String paypassword;
	//银行卡表编码
	private String bankCardCode;
	//用户账号状态0:未删除，1:已删除
	private Integer deleteType;
	//创建时间/可以判断是否是新用户
	private Date createTime;
	//账号类型 1 公司 2 个人 默认个人
	public static final int CHOOSE_TYPE_COMPANY=1;
	public static final int CHOOSE_TYPE_PERSONAL=2;
	private Integer chooseType;
	//性别 1 男 2 女
	private Integer gender;
	//签名
	private String autograph;
	//出生日期
	private Date birth;
	//职业
	private String occupation;
	//头像地址/也是公司logo
	private String headImgUrl;
	//背景图 个人中心那张大图
	private String backgroundImgUrl;
	//跑腿服务是否开启 0 未开启 1 开启
	private Integer butlerStatus;
	/**粉丝数量*/
	private Integer fansCount;
	/**云信token*/
	private String yunXinToken;

	public TbUser() {
	}

	public TbUser(String password, String email, Integer chooseType, Date birth, Integer gender, String occupation) {
		this.setPassword(DigestUtils.sha256Hex(password));
		this.setEmail(email);
		this.setDeleteType(0);
		this.setUserCode(UUID.randomUUID().toString());
		this.setCreateTime(new Date());
		this.setChooseType(chooseType);
		this.fansCount=0;
		this.userName=email;
		this.setHeadImgUrl(GidgabsContants.HEAD_IMG_DEFAULT);
		this.birth=birth;
		this.gender=gender;
		this.occupation=occupation;
	}

	/**
	 * 设置：
	 */
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	/**
	 * 获取：
	 */
	public Integer getUserId() {
		return userId;
	}
	/**
	 * 设置：用户编码
	 */
	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}
	/**
	 * 获取：用户编码
	 */
	public String getUserCode() {
		return userCode;
	}
	/**
	 * 设置：昵称
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}
	/**
	 * 获取：昵称
	 */
	public String getUserName() {
		return userName;
	}

	public String getYunXinToken() {
		return yunXinToken;
	}

	public void setYunXinToken(String yunXinToken) {
		this.yunXinToken = yunXinToken;
	}

	public Integer getFansCount() {
		return fansCount;
	}

	public void setFansCount(Integer fansCount) {
		this.fansCount = fansCount;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * 设置：电话
	 */
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	/**
	 * 获取：电话
	 */
	public String getMobile() {
		return mobile;
	}
	/**
	 * 设置：登录密码
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	/**
	 * 获取：登录密码
	 */
	public String getPassword() {
		return password;
	}
	/**
	 * 设置：支付密码
	 */
	public void setPaypassword(String paypassword) {
		this.paypassword = paypassword;
	}
	/**
	 * 获取：支付密码
	 */
	public String getPaypassword() {
		return paypassword;
	}

	public String getBankCardCode() {
		return bankCardCode;
	}

	public void setBankCardCode(String bankCardCode) {
		this.bankCardCode = bankCardCode;
	}
	/**
	 * 设置：用户账号状态0:未删除，1:已删除
	 */
	public void setDeleteType(Integer deleteType) {
		this.deleteType = deleteType;
	}
	/**
	 * 获取：用户账号状态0:未删除，1:已删除
	 */
	public Integer getDeleteType() {
		return deleteType;
	}
	/**
	 * 设置：创建时间/可以判断是否是新用户
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	/**
	 * 获取：创建时间/可以判断是否是新用户
	 */
	public Date getCreateTime() {
		return createTime;
	}
	/**
	 * 设置：账号类型 1 公司 2 个人 默认个人
	 */
	public void setChooseType(Integer chooseType) {
		this.chooseType = chooseType;
	}
	/**
	 * 获取：账号类型 1 公司 2 个人 默认个人
	 */
	public Integer getChooseType() {
		return chooseType;
	}
	/**
	 * 设置：性别 1 男 2 女
	 */
	public void setGender(Integer gender) {
		this.gender = gender;
	}
	/**
	 * 获取：性别 1 男 2 女
	 */
	public Integer getGender() {
		return gender;
	}
	/**
	 * 设置：签名
	 */
	public void setAutograph(String autograph) {
		this.autograph = autograph;
	}
	/**
	 * 获取：签名
	 */
	public String getAutograph() {
		return autograph;
	}
	/**
	 * 设置：出生日期
	 */
	public void setBirth(Date birth) {
		this.birth = birth;
	}
	/**
	 * 获取：出生日期
	 */
	public Date getBirth() {
		return birth;
	}
	/**
	 * 设置：职业
	 */
	public void setOccupation(String occupation) {
		this.occupation = occupation;
	}
	/**
	 * 获取：职业
	 */
	public String getOccupation() {
		return occupation;
	}
	/**
	 * 设置：头像地址/也是公司logo
	 */
	public void setHeadImgUrl(String headImgUrl) {
		this.headImgUrl = headImgUrl;
	}
	/**
	 * 获取：头像地址/也是公司logo
	 */
	public String getHeadImgUrl() {
		return headImgUrl;
	}
	/**
	 * 设置：背景图 个人中心那张大图
	 */
	public void setBackgroundImgUrl(String backgroundImgUrl) {
		this.backgroundImgUrl = backgroundImgUrl;
	}
	/**
	 * 获取：背景图 个人中心那张大图
	 */
	public String getBackgroundImgUrl() {
		return backgroundImgUrl;
	}
	/**
	 * 设置：跑腿服务是否开启 0 未开启 1 开启
	 */
	public void setButlerStatus(Integer butlerStatus) {
		this.butlerStatus = butlerStatus;
	}
	/**
	 * 获取：跑腿服务是否开启 0 未开启 1 开启
	 */
	public Integer getButlerStatus() {
		return butlerStatus;
	}

	@Override
	protected Serializable pkVal() {
		return this.userId;
	}


	public TbUserDto toDto(){
		TbUserDto tbuserdto=new TbUserDto();
		tbuserdto.setUserName(this.getUserName());
		tbuserdto.setAutograph(this.getAutograph());
		tbuserdto.setUserId(this.getUserId());
		tbuserdto.setUserCode(this.getUserCode());
		tbuserdto.setMobile(this.getMobile());
		tbuserdto.setDeleteType(this.getDeleteType());
		tbuserdto.setCreateTime(this.getCreateTime());
		tbuserdto.setChooseType(this.getChooseType());
		tbuserdto.setBankCardCode(this.getBankCardCode());
		tbuserdto.setGender(this.getGender());
		tbuserdto.setBirth(this.getBirth());
		tbuserdto.setOccupation(this.getOccupation());
		tbuserdto.setHeadImgUrl(this.getHeadImgUrl());
		tbuserdto.setButlerStatus(this.getButlerStatus());
		tbuserdto.setBackgroundImgUrl(this.getBackgroundImgUrl());
		tbuserdto.setFansCount(this.getFansCount());
		tbuserdto.setYunXinToken(this.getYunXinToken());
		return tbuserdto;
	}

	public void edit(TbUserDto tbUserDto) {
		if (StringUtils.isNotBlank(tbUserDto.getPassword())){
			this.password=DigestUtils.sha256Hex(tbUserDto.getPassword());
		}
		if (StringUtils.isNotBlank(tbUserDto.getUserName())){
			this.userName=tbUserDto.getUserName();
		}
		if (StringUtils.isNotBlank(tbUserDto.getAutograph())){
			this.autograph=tbUserDto.getAutograph();
		}
		if (StringUtils.isNotBlank(tbUserDto.getHeadImgUrl())){
			this.headImgUrl=tbUserDto.getHeadImgUrl();
		}
		if (tbUserDto.getBirth()!=null){
			this.birth=tbUserDto.getBirth();
		}if (tbUserDto.getGender()!=null){
			this.gender=tbUserDto.getGender();
		}
	}
}
